package com.cmj.controller;

import com.cmj.annotation.SystemLog;
import com.cmj.domain.ResponseResult;
import com.cmj.domain.entity.User;
import com.cmj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户管理
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /***
     * 获取用户信息
     * @return 返回用户信息
     */
    @GetMapping("/userInfo")
    public ResponseResult userInfo(){
        return userService.userInfo();
    }

    /**
     * 更新用户信息
     * @param user 用户信息{
     *     "avatar":"https://sg-blog.....",
     *     "email":"23412332@qq.com",
     *     "id":"1",
     *     "nickName":"sg333",
     *     "sex":"1"
     * }
     * @return 操作结果
     */
    @PutMapping("/userInfo")
    @SystemLog(businessName = "更新用户")
    public ResponseResult updateUserInfo(@RequestBody User user){
        return userService.updateUserInfo(user);
    }

    /**
     * 注册
     * @param user {
     *   "email": "string",
     *   "nickName": "string",
     *   "password": "string",
     *   "userName": "string"
     * }
     * @return 操作结果
     */
    @PostMapping("/register")
    public ResponseResult register(@RequestBody User user){
        return userService.register(user);
    }
}
